//
//  QCCheckController.swift
//  爱汽车
//
//  Created by tucici on 2023/12/31.
//

import UIKit
import TCCKit
class QCCheckResultController: QCViewController {
    var array = [String]()
    var errors = [String]()
    private var data = [String](){
        didSet{
            collectionView.reloadData()
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
    }
    override func initUI() {
        data = errors.count > 0 ? errors : array
        flowLayout.scrollDirection = .vertical
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.isPagingEnabled = true
        collectionView.backgroundColor = .clear
        collectionView.isScrollEnabled = false
        collectionView.register(QCCheckResultCell.self, forCellWithReuseIdentifier: QCCheckResultCell.ID())
        
        collectionView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    override func backBtnAction() {
        CCHud.start(LS("请稍后..."), stopTime: 1.5) {[weak self] in
            guard let self = self else{return}
            navigationController?.popToRootViewController(animated: true)
        }
    }
    
}
//MARK: - UICollectionViewDataSource
extension QCCheckResultController:UICollectionViewDataSource
{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return data.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier:QCCheckResultCell.ID(), for:indexPath) as! QCCheckResultCell
        cell.success = errors.count <= 0
        cell.content.text = data[indexPath.row]
        return cell
    }
}
//MARK: - UICollectionViewDelegate
extension QCCheckResultController:UICollectionViewDelegate
{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        
    }
}
//MARK: - UICollectionViewDelegateFlowLayout
extension QCCheckResultController:UICollectionViewDelegateFlowLayout
{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
        return  CGSize(width:kUIScreenWidth , height: 60)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat{
        return 0
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
    {
        return UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
    }
}
